import { DisableUUid32Dto, PageData } from "~/rest";
import { WithPasterList, WithStockTotal } from "~/view.with";

import { Gateway, getGateway } from "@/droplet-bus/core.define";
import { TonTpl } from "@/river-ton/schema.tpl";
import { TonOrder, TonOrderGroup } from "@/river-ton/schema.order";
import {
  putSaleRpcDto,
  postSaleRpcDto,
  putAdjustRpcDto,
  putProcessRpcDto,
  postProcessRpcDto,
  putPurchaseRpcDto,
  postPurchaseRpcDto,
  putSaleReturnRpcDto,
  doTonSkuCreationRes,
  postSaleReturnRpcDto,
} from "@/river-ton/rpc.sku";
import { getTplPageRpcDto } from "@/river-ton/rpc.tpl";

import { OceanGateway } from "./core.define";

export const GateRiverTonGateway: Gateway = getGateway(OceanGateway, "ocean_gate_river_ton");
export type getRiverTonTplDto = getTplPageRpcDto & { tonOrderGroupId?: TonOrderGroup["id"] };
export type putPurchaseDto = putPurchaseRpcDto;
export type postPurchaseDto = postPurchaseRpcDto;

export type putAdjustDto = putAdjustRpcDto;
export type putProcessDto = putProcessRpcDto;
export type postProcessDto = postProcessRpcDto;

export type putSaleDto = putSaleRpcDto;
export type postSaleDto = postSaleRpcDto;
export type putSaleReturnDto = putSaleReturnRpcDto;
export type postSaleReturnDto = postSaleReturnRpcDto;

export interface GateRiverTonInterfaceWithDerive<T> {
  /** 先去RiverTon查询商品模版，然后再去RiverStock进行组装 */
  getTplList(dto: T & getRiverTonTplDto): Promise<PageData<WithPasterList & WithStockTotal & TonTpl>>;

  /** 逻辑删除订单 */
  disableOrderSync(dto: T & DisableUUid32Dto): Promise<{ updated: TonOrder }>;

  /** 采购 */
  putPurchaseSkuSync(dto: T & putPurchaseDto): Promise<doTonSkuCreationRes>;
  postPurchaseSkuSync(dto: T & postPurchaseDto): Promise<doTonSkuCreationRes>;

  /** 调整 */
  putAdjustSkuSync(dto: T & putAdjustDto): Promise<doTonSkuCreationRes>;

  /** 加工 */
  putProcessSkuSync(dto: T & putProcessDto): Promise<doTonSkuCreationRes>;
  postProcessSkuSync(dto: T & postProcessDto): Promise<doTonSkuCreationRes>;

  /** 销售 */
  putSaleSkuSync(dto: T & putSaleDto): Promise<doTonSkuCreationRes>;
  postSaleSkuSync(dto: T & postSaleDto): Promise<doTonSkuCreationRes>;

  /** 销售退货 */
  putSaleReturnSkuSync(dto: T & putSaleReturnDto): Promise<doTonSkuCreationRes>;
  postSaleReturnSkuSync(dto: T & postSaleReturnDto): Promise<doTonSkuCreationRes>;
}
